﻿package 
{
	import as3.collections.IMap;
	import as3.collections.LinkedMap;
	import commands.request.IRequestable;
	import commands.request.IRequestCommands;
	import commands.SearchProductCommand;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.XMLSocket;
	
	/**
	 * ...
	 * @author Rami
	 */
	public class Main extends Sprite 
	{
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			//Test1
			//var xmlsock:XMLSocket = new XMLSocket();
			//xmlsock.connect("127.0.0.1", 9123);
			//	xmlsock.send("RAMI!");
			//Test2
			var connector : SocketConnector = new SocketConnector();
			var requests : IRequestCommands =  connector.getProactor().createNewRequestCommandsSet();
			var request : IRequestable = connector.getProactor().getRequestCommandByName(SearchProductCommand.SEARCH_COMMAND);
			var args:IMap = new LinkedMap();
			args.addItem(SearchProductCommand.PRODUCT_NAME_START_ARGUMENT, "ram");
			requests.addRequest(request , args);
			connector.getProactor().sendCommands(requests);
			
			//connector.sendCommand("RAMI!!!!!!!!");
//			 //var productNameStarts:XML = new XML("<productNameStarts></productNameStarts>");
			 //var text:XML = new XML("<command></command>");
			 //text.productNameStarts = "ramiiii";
			 
			 //text.@name = "R1";
			//trace(text.toString());
			
		}
	}
}